package com.cr.common.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 阿里云短信服务相关配置
 */
@Component
@ConfigurationProperties(prefix = "aliyun.sms")
public class AliyunSmsConfig {

    /** AccessKeyId */
    private String accessKeyId;

    /** AccessKeySecret */
    private String accessKeySecret;

    /** 地区 */
    private String regionId;

    /** 签名名称 */
    private String signName;

    /** 模板Code */
    private String templateCode;

    @Bean
    public IAcsClient smsClient() throws ClientException {
        // 使用读取到的 regionId、accessKeyId 和 accessKeySecret 创建 DefaultProfile 实例
        IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        // 使用创建的 DefaultProfile 实例创建 DefaultAcsClient 实例，作为短信服务的客户端
        return new DefaultAcsClient(profile);
    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public void setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
    }

    public String getRegionId() {
        return regionId;
    }

    public void setRegionId(String regionId) {
        this.regionId = regionId;
    }

    public String getSignName() {
        return signName;
    }

    public void setSignName(String signName) {
        this.signName = signName;
    }

    public String getTemplateCode() {
        return templateCode;
    }

    public void setTemplateCode(String templateCode) {
        this.templateCode = templateCode;
    }
}
